<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends PublicController {
    public function index(){
		//判断模板加载文件
		$this->assign("k",CONTROLLER_NAME);
		$this->assign("f",ACTION_NAME);
		
		$this->navshow();
		$this->tuishow();
		$this->wxjshow();
		$this->liebiaoshow();
		
        $this->display();
    }
	//导航输出
	public function navshow(){
		$info = M('nav')->select();
		$this->assign("info",$info);
	}
	//推荐类商品对应输出
	public function tuishow(){
		
		$rec = M("recommend")->select();
		//按分类组合到不同数组内
		$arrlist = array();
		foreach($rec as $k=>$v){
			$id = $v['id'];
			$tuijian = M("tuijianleilist")->where("t_id = '$id'")->select();
			$arrlist[$k] = $tuijian;
			
		}
		$this->assign("rec",$rec);   //推荐类类型输出
		$this->assign("tuijian",$arrlist); //推荐类详情输出
	}
	
	
	
	//xin
	public function wxjshows(){
		$wuxianzhu = M('fenlei')->where("p_id = '0,'")->select();
		
		$arr = $this->xin($wuxianzhu);
	}
	//xin
	public function xin($arr){
		
		$wuxiantotal = array();
		
		foreach($arr as $k=>$v){
			
			$id = $v['id'];
			$res = M('fenlei')->field('name,id')->where("p_id = '0,$id,'")->select(); //需要组合他的id+pid
			$wuxiantotal[$k] = $v;
			if(!empty($res)){
				
				
				$wuxiantotal[$k]["zi"] = $this->xin($res);
				
			}
			
			//$wuxiantotal[$v['name']] = $res;
			
			
			
			/* foreach($res as  $k1=>$v1){
				
				$ziid = $v1['id'];
				$arr = M('fenlei')->field('name,id')->where("p_id = '0,$id,$ziid,'")->select();
				$wuxiantotal[$v['name']][$v1['name']] = $arr;
					
			} */
			
		}
		
		//var_dump($wuxiantotal);
		return $wuxiantotal;
		
		
		
	}
	
	
	//商品列表页输出
	public function liebiaoshow(){
		$liebiao = M('listinfo')->select();
		$this->assign("liebiao",$liebiao);
		//var_dump($liebiao);
	}
}